package com.gettong.test.SpringCloudCommon.feign.fallback;

import com.gettong.test.SpringCloudCommon.entity.User;
import com.gettong.test.SpringCloudCommon.feign.UserFeign;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by gettong on 2019/11/30.
 */
@Component
public class UserFeignFallbackFactory implements FallbackFactory<UserFeign> {
    @Override
    public UserFeign create(Throwable throwable) {
        return new UserFeign() {
            @Override
            public List<User> list() {
                System.out.println("UserFeign-list异常：" + throwable.getMessage());
                return null;
            }

            @Override
            public User get(Long id) {
                System.out.println("UserFeign-get异常：" + throwable.getMessage() + "，参数id：" + id);
                return null;
            }

            @Override
            public void save(User user) {
                System.out.println("UserFeign-ave异常：" + throwable.getMessage() + "，参数user：" + user);
            }

            @Override
            public void delete(Long id) {
                System.out.println("UserFeign-delete异常：" + throwable.getMessage() + "，参数id：" + id);
            }
        };
    }
}
